//* keyboard.js

var keyboard = (function(){
    var keyboardObj = document.getElementById('keyboard'), _inputID, _shiftStatus = false, _capsLock = false;

    // 显示虚拟键盘
    var _showKeyboard = function(){
        keyboardObj.style.display = 'block';
    }

    // 隐藏虚拟键盘
    var _hideKeyboard = function(){
        keyboardObj.style.display = 'none';
    }

    // 输入新内容
    var _inputNewContent = function(str){
        document.getElementById(_inputID).innerHTML = str;
    }

    // 添加classname
    function _addClass(obj, cls){
        var obj_class = obj.className,
        blank = obj_class != '' ? ' ' : '';
        var added = obj_class + blank + cls;
        obj.className = added;

    }

    // 删除classname
    function _removeClass(obj, cls){
        var obj_class = ' ' + obj.className + ' ';
        obj_class = obj_class.replace(/(\s+)/gi, ' ');
        var removed = obj_class.replace(' ' + cls + ' ', ' ');
        removed = removed.replace(/(^\s+)|(\s+$)/g, '');
        obj.className = removed;
    }

    // 为按钮添加active
    function _addActive(cls, keycode){
        var keys = document.getElementsByClassName(cls);
        for(var o of keys){
            if(o.getAttribute('data-kid') == keycode){
                _addClass(o, 'active');
            }
        }
    }

    // 为按钮取消active
    function _removeActive(cls, keycode){
        var keys = document.getElementsByClassName(cls);
        for(var o of keys){
            if(o.getAttribute('data-kid') == keycode){
                _removeClass(o, 'active');
            }
        }
    }

    var keyboard = function(){}

    // 输入框绑定键盘
    keyboard.prototype.addKeyboard = function(id){
        _inputID = id
        var inputObj = document.getElementById(id);
        inputObj.onclick = _showKeyboard();
        _bindEvent();
    }

    return keyboard;
})()